const path = require('path');
const root = path.resolve(__dirname);
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const rm = require('rimraf')

rm(path.join(root, 'dist'), err => {
    if (err) throw err;
    console.log('/dist目录删除成功')
});

module.exports = {
    entry: path.resolve(root, 'src/main.js'),
    output: {
        path: path.resolve(root, 'dist'),
        filename: 'bundle.js',
        publicPath: './'
    },
    module: {
        rules: [
            {
                test: /\.html$/i,
                use: [
                    'html-loader',
                    'ejs-loader'
                ]
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                oneOf: [
                    {
                        resourceQuery: /base64/,
                        use: ['url-loader']
                    },
                    {
                        use: [{
                            loader: 'url-loader',
                            options: {
                                limit: 1,
                                name: 'img/[name].[hash:7].[ext]'
                            }
                        }]
                    }
                ]
            },
            {
                test: /\.css$/,
                use: [
                    'vue-style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            modules: {
                                localIdentName: 'css/[name].[hash:7].[ext]'
                            }
                        }
                    }
                ]
            },
            {
                test: /\.scss$/,
                use: [
                    'vue-style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            modules: {
                                localIdentName: 'css/[name].[hash:7].[ext]'
                            }
                        }
                    },
                    'sass-loader'
                ]
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 1,
                    name: 'fonts/[name].[ext]',
                },
            },
            {
                test: /\.(svg)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 1,
                    name: 'svg/[name].[ext]',
                },
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
   template:path.resolve(root,"public/index.html")
        })
    ]
};